package com.lmc.gobang.service;

import com.lmc.gobang.mapper.UserMapper;
import com.lmc.gobang.model.User;
import com.lmc.gobang.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;
    public boolean registerUser(User user) {
        //调用加密工具对密码进行加密
        String encryptedPassword = SecurityUtil.encryptPassword(user.getPassword());
        user.setPassword(encryptedPassword);
        if (userMapper.registerUser(user)) {
            return true;
        }
        return false;
    }

    public User getUserByUsername(String username) {
        return userMapper.getUserByUsername(username);
    }
}
